{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "(10, 10, 10)\n",
      "1000\n",
      "uint8\n",
      "1\n",
      "<memory at 0x0000000005BEC228>\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "arr = np.zeros((10,10,10),dtype=\"uint8\")\n",
    "print(arr.ndim) #输出数组的维数 轴数\n",
    "print(arr.shape) #输出数组的维度 形状\n",
    "print(arr.size) #输出数组的元素个数\n",
    "print(arr.dtype) #输出数组的值类型\n",
    "print(arr.itemsize)# 元素的字节大小\n",
    "print(arr.data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1]\n",
      " [2 3]\n",
      " [4 5]\n",
      " [6 7]\n",
      " [8 9]]\n",
      "[[0.77978618 0.64088466 0.5710741  0.5866374  0.34361262]\n",
      " [0.62269382 0.51994874 0.61356735 0.96318496 0.7235785 ]]\n",
      "[10.  10.5 11.  11.5 12.  12.5 13.  13.5 14.  14.5 15.  15.5 16.  16.5\n",
      " 17.  17.5 18.  18.5 19.  19.5 20. ]\n",
      "[[0 0 0 0 0]\n",
      " [0 0 0 0 0]]\n",
      "[[1 0 0 0 0]\n",
      " [0 1 0 0 0]\n",
      " [0 0 1 0 0]\n",
      " [0 0 0 1 0]\n",
      " [0 0 0 0 1]]\n"
     ]
    }
   ],
   "source": [
    "# 创建数组\n",
    "\n",
    "# 1.直接通过列表创建  array()函数\n",
    "arr1 = np.array([1,2,3,4,5,6,7,8,9,0])\n",
    "\n",
    "# 2.范围创建\n",
    "arr2 = np.arange(10).reshape(5,2)\n",
    "print(arr2)\n",
    "\n",
    "# 3.随机值创建\n",
    "arr3 = np.random.rand(10).reshape(2,5)\n",
    "print(arr3)\n",
    "\n",
    "# 4.间隔创建\n",
    "arr4 = np.linspace(10,20,num=21)\n",
    "# arr4 = np.linspace(10,20,num=20,endpoint = False,retstep = True)\n",
    "print(arr4)\n",
    "\n",
    "# 5.创建Zero数组 zeros/zeros_like/ones/ones_like()\n",
    "arr5 = np.zeros((5,5),dtype=\"int\")\n",
    "arr6 = np.zeros_like(arr3,dtype=\"int\")\n",
    "print(arr6)\n",
    "\n",
    "# 6. 创建单位矩阵\n",
    "arr7 = np.eye(5,dtype=\"int\")\n",
    "print(arr7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0]\n",
      " [0 0]\n",
      " [0 0]\n",
      " [0 0]\n",
      " [0 0]]\n",
      "[[0 0 0 0 0]\n",
      " [0 0 0 0 0]]\n",
      "[[0 1 2 3]\n",
      " [4 5 6 7]\n",
      " [8 9 0 1]]\n",
      "[[0 0 0 0 0]\n",
      " [0 0 0 0 0]]\n",
      "[[0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0.]]\n"
     ]
    }
   ],
   "source": [
    "# 1. T 数组转秩\n",
    "arr8 = np.arange(10)\n",
    "arr9 = np.zeros((2,5), dtype = np.int)\n",
    "print(arr9.T)\n",
    "\n",
    "# 2. reshape\n",
    "print(arr9.reshape(2,5))\n",
    "\n",
    "# 3. resize()\n",
    "print(np.resize(arr8,(3,4))) # 数量不够会进行默认排序\n",
    "\n",
    "# 4. copy\n",
    "arr10 = arr9.copy()\n",
    "print(arr10)\n",
    "\n",
    "# 5.astype 数据类型转换\n",
    "arr11 = arr10.astype(\"float16\")\n",
    "print(arr11)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n",
      "[[0 1 2 3 4]\n",
      " [5 6 7 8 9]]\n",
      "[array([[ 0,  1],\n",
      "       [ 4,  5],\n",
      "       [ 8,  9],\n",
      "       [12, 13]]), array([[ 2,  3],\n",
      "       [ 6,  7],\n",
      "       [10, 11],\n",
      "       [14, 15]])]\n",
      "[array([[0, 1, 2, 3],\n",
      "       [4, 5, 6, 7]]), array([[ 8,  9, 10, 11],\n",
      "       [12, 13, 14, 15]])]\n"
     ]
    }
   ],
   "source": [
    "# 数组堆叠\n",
    "a = np.arange(5)\n",
    "b = np.arange(5,10)\n",
    "print(np.hstack((a,b))) #横向堆叠\n",
    "print(np.vstack((a,b))) #竖向堆叠\n",
    "\n",
    "c = np.arange(16).reshape(4,4)\n",
    "print(np.hsplit(c,2))\n",
    "print(np.vsplit(c,2))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
